/*Copyright (C) 2013-2021 LZE*/
#include<bits/stdc++.h>
#define fo(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
#define INF 0x7fffffff
#define mod 1000000007
#define eps 1e-6
typedef unsigned long long ull;
typedef long long ll;
struct TreeNode{
	vector<int>son;
	int father,dep;
}node[500010];
bool vis[500010];
int n,m,s;
void init_dep(int step,int dep){
	if(vis[step])return;
	vis[step] = 1;
	node[step].dep = dep;
	int len = node[step].son.size();
	for(int i = 0;i < len;i++){
		if(!vis[node[step].son[i]]){
			node[node[step].son[i]].father = step;
			init_dep(node[step].son[i],dep + 1);
		}
	}
}
void init_node(int &node1,int &node2){
	int step,end;
	if(node[node1].dep < node[node2].dep){
		step = node2;
		end = node[node1].dep;
		for(;node[step].dep != end;step = node[step].father);
		node2 = step;
	}
	else if(node[node1].dep > node[node2].dep){
		step = node1;
		end = node[node2].dep;
		for(;node[step].dep != end;step = node[step].father);
		node1 = step;
	}
	else return;
}
int LCA(int node1,int node2){
	if(node1 == node2)return node1;
	for(;node[node1].father != node[node2].father;node1 = node[node1].father,node2 = node[node2].father);
	return node[node1].father;
}
int main(){
	int u,v;
	scanf("%d%d%d",&n,&m,&s);
	for(int i=1;i<=n-1;i++){
		scanf("%d%d",&u,&v);
		node[v].son.push_back(u);
		node[u].son.push_back(v);
	}
	init_dep(s,1);
	for(int i = 1;i <= m;i++){
		scanf("%d%d",&u,&v);
		init_node(u,v);
		printf("%d\n",LCA(u,v));
	}
	return 0;
}